package com.edu.zju.scs.panacea.service.manage;


import com.edu.zju.scs.panacea.entity.BaseResult;
import com.edu.zju.scs.panacea.entity.manage.Admin;
import com.edu.zju.scs.panacea.mapper.manage.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

@Service
public class AdminService {

    @Autowired
    private AdminMapper adminMapper;

    public BaseResult isAdmin(String name, String password, HttpSession session) {
        Admin admin = adminMapper.selectAdmin(name, password);
        BaseResult baseResult = new BaseResult();
        if (admin == null) {
            baseResult.error("用户名或密码错误");
        }
        else {
            baseResult.success(admin);
            session.setAttribute("admin", admin);
        }
        return baseResult;
    }
}
